clear all
set more off
set mem 100m
tempfile temp

/* 

This dofile categorizes identity variables using raw data from ENAHO's module on democracy  (gobernabilidad democracia y transparencia, modulo 85)


*/

local enaho ../../../data/enaho
local working ../working


** 2004-2006
forvalues x = 2004/2006 {
	use `enaho'/`x'/enaho01b-`x'-1, clear
	gen year = `x'
	
	tab p28, gen(p28_)
	rename p28_1 idt_ctry
	rename p28_2 idt_dpto
	rename p28_3 idt_race0
	rename p28_4 idt_fait0
	
	gen weightg = facgob
	
	destring conglome vivienda hogar codperso, replace
	keep conglome vivienda hogar codperso year weightg idt_*
	save trust_`x', replace

}	

** 2007-2016
forvalues x = 2007/2016 {
	use `enaho'/`x'/enaho01b-`x'-1, clear
	gen year = `x'
	
	tab p21, gen(p21_)
	rename p21_1 idt_regi
	rename p21_2 idt_race1
	rename p21_3 idt_comm1
	rename p21_4 idt_fait1
	
	cap gen weightg = factor07
	cap gen weightg = facgob07
	cap gen weightg = famiegob07
	
	destring conglome vivienda hogar codperso, replace force
	keep conglome vivienda hogar codperso year weightg idt_*
	save trust_`x', replace
}

use trust_2004, clear
forvalues x = 2005/2016 {
	append using trust_`x'
}	

forvalues x = 2004/2016 {
	erase trust_`x'.dta
}	

** SAVE
compress
save `working'/identity, replace
